<template>
  <div class="my-pseudo-3d-principle">
    <button @click="doNext">下一步</button>
    <div class="tips">{{tipsArr[next]}}</div>
    <div class="box" :class="`next${next}`">
      <div v-for="n in 20" :key="n" class="text">光</div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Pseudo3DPrinciple",
  describe: "伪3D原理演示",
  path: "/pseudo3d/principle",
  data() {
    return {
      next: 0,
      fontSize: 150,
      tipsArr: [
        'CSS伪3D原理演示',
        '第一步：创建20个“光”字',
        '第二步：将文字延x轴3D旋转45度角',
        '第三步：将文字堆叠在一起',
        '第四步：将文字延z轴依次平移1px',
        '第五步：给文字加上阴影',
      ]
    }
  },
  methods: {
    doNext() {
      if (++this.next === 6) {
        this.next = 0;
      }
    }
  }
}
</script>

<style lang="scss">
.my-pseudo-3d-principle{
  width: 100%;
  height: 100%;
  background-color: #03081E;
  overflow: hidden;
  position: relative;
  transform-style: preserve-3d;
  perspective-origin: center center;
  perspective: 2000px;
  .tips{
    font-size: 30px;
    width: 100%;
    text-align: center;
    color: #fff;
    padding-top: 10px;
    position: absolute;
    top: 0;
    left: 0;
  }
  button {
    font-size: 20px;
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    transform-style: preserve-3d;
  }
  .box{
    position: absolute;
    top: 50%;
    left: 50%;
    transform-style: preserve-3d;
    perspective-origin: center center;
    perspective: 2000px;
    transition: all 500ms;
    &.next0,
    &.next5{
      .text{
        text-shadow: 0 0 2px rgba(0,0,0,0.7);
        @for $i from 0 to 20 {
          &:nth-child(#{$i + 1}) {
            transform: rotateX(45deg) translate3d(0, 0, #{$i}px);
          }
        }
      }
    }
    &.next1 .text{
      @for $i from 0 to 20 {
        &:nth-child(#{$i + 1}) {
          transform: rotateX(0deg) translate3d(#{floor($i % 5 - 2) * 150}px, #{floor($i / 5 - 2) * 150}px, #{$i}px);
        }
      }
    }
    &.next2 .text{
      @for $i from 0 to 20 {
        &:nth-child(#{$i + 1}) {
          transform: rotateX(45deg) translate3d(#{floor($i % 5 - 2) * 150}px, #{floor($i / 5 - 2) * 150}px, #{$i}px);
        }
      }
    }
    &.next3 .text{
      @for $i from 0 to 20 {
        &:nth-child(#{$i + 1}) {
          transform: rotateX(45deg) translate3d(0px, 0px, #{($i - 10) * 20}px);
        }
      }
    }
    &.next4 .text{
      @for $i from 0 to 20 {
        &:nth-child(#{$i + 1}) {
          transform: rotateX(45deg) translate3d(0px, 0px, #{$i}px);
        }
      }
    }
    &.next0 .text{
      @for $i from 0 to 20 {
        &:nth-child(#{$i + 1}) {
          animation: my-pseudo-3d-principle-animation#{$i} 10s linear infinite;
        }
      }
    }
  }
  .text{
    color: #fff;
    font-size: 150px;
    text-shadow: 0 0 0 #000;
    position: absolute;
    top: - 75px;
    left: -75px;
    transform: rotateX(45deg) translateZ(0);
    transition: all 2000ms;
    @for $i from 0 to 20 {
      &:nth-child(#{$i + 1}) {
        color: rgb(($i * 12), 255 ,(20 - $i) * 12);
      }
    }
  }
}

@for $i from 0 to 20 {
  @keyframes my-pseudo-3d-principle-animation#{$i} {
    from {
      transform: rotateX(45deg) rotateZ(0deg) translate3d(0px, 0px, #{$i}px);
    }
    to {
      transform: rotateX(45deg) rotateZ(360deg) translate3d(0px, 0px, #{$i}px);
    }
  }
}
</style>